<script setup name="addSysCode">


import {useDict} from "@/utils/dict.js";
import {addSysCode, editSysCode} from "@/api/admin/SysCode.js";
import modal from "@/plugins/modal.js";


let props = defineProps({
  title: {
    type: String,
    default: ""
  },
  form: {
    type: Object,
    default: {}
  },
  state: {
    type: Number,
    default: 0
  }
});

const emits = defineEmits(["refreshTable"])

let open = defineModel('open', {type: Boolean, default: false})


const submitForm = () => {
  if (props.state === 0) {
    addSysCode(props.form)
        .then(res => {
          open.value = false;
          modal.msgSuccess("添加成功");
          emits("refreshTable")
        })
        .catch((res) => {
        })
  } else if (props.state === 1) {
    editSysCode(props.form)
        .then(res => {
          open.value = false;
          modal.msgSuccess("修改成功");
          emits("refreshTable")
        })
        .catch((res) => {
        })
  }

}

const cancel = () => {
  open.value = false;
}
</script>

<template>
  <!-- 添加或修改岗位对话框 -->
  <el-dialog :title="title" v-model="open" width="500px" append-to-body>
    <el-form :model="props.form" label-width="120px">
      <el-form-item label="代码类型" prop="postName">
        <el-input v-model="props.form.codeType" placeholder="请输入代码类型" :disabled="props.state===1"/>
      </el-form-item>
      <el-form-item label="代码名称" prop="postCode">
        <el-input v-model="props.form.typeName" placeholder="请输入代码名称"/>
      </el-form-item>
      <el-form-item label="代码描叙" prop="postSort">
        <el-input v-model="props.form.codeDescription"/>
      </el-form-item>
      <el-form-item label="是否可维护" prop="status">
        <el-radio-group v-model="props.form.iscustomize">
          <el-radio
              :key="'0'"
              :value="'0'"
          >是
          </el-radio>
          <el-radio
              :key="'1'"
              :value="'1'"
          >否
          </el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style scoped lang="scss">

</style>